namespace AltNetUK.Controllers
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Web;
    using System.Web.Mvc;
    using SimpleWebServices;
    using SimpleWebServices.Configuration;
    using SimpleWebServices.Models;
    using SimpleWebServices.Web.Mvc;
    using AltNetUK.Models;

    [InternalServerError]
    [Allow(Methods = "GET, HEAD, OPTIONS")]
    [CacheControl, ContentLanguage, ContentMD5]
    public sealed class HomeController : Controller
    {
        [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "This needs to be an instance member.")]
        public ActionResult LanguageNegotiation()
        {
            return new SeeOtherResult("2009.en");
        }

        [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "This needs to be an instance member.")]
        public ActionResult ContentNegotiation(CultureInfo language)
        {
            if (null == language)
            {
                throw new ArgumentNullException("language");
            }
            else if (CultureInfo.InvariantCulture == language)
            {
                throw new ArgumentOutOfRangeException("language");
            }

            string location = string.Format(CultureInfo.InvariantCulture, "2009.{0}.html", language.Name);
            return new SeeOtherResult(location);
        }

        public ActionResult HtmlRepresentation(CultureInfo language)
        {
            if (null == language)
            {
                throw new ArgumentNullException("language");
            }
            else if (CultureInfo.InvariantCulture == language)
            {
                throw new ArgumentOutOfRangeException("language");
            }

            Home model = Home.New(this.Request.Url);
            this.Response.StatusCode = (int)model.Status;

            return View(model);
        }
    }
}